<?php
/*
	Aurus CMS - free OOP CMS
	Copyright (C) 2010  Nestor Yanchuk

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 2 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
if (! defined('ROOT')) die();
if (isset($_POST['data'])) {
	if (!empty($_POST['data']['groupname'])) {
		Cache::clear('usergroups');
		Mysql::getInstance()->insert('usergroups',array('groupallow' => serialize($_POST['data'])));
		Aurus::getInstance()->addContent( Adminarea::getInstance()->adminInfo(__('Групу додано'),0,LINK_ROOT.'adminarea/?do=users&amp;mod=groups',1));
	} else {
		Aurus::getInstance()->addContent( Adminarea::getInstance()->adminInfo(__('Дайте групі назву')));
	}
} else {
	$tr = '';
	$td = '';
	foreach (Users::getInstance()->USERGROUPDATA as $name => $arrs){
		list($desc,$fieldtype,$vars) = $arrs;
		switch ($fieldtype) {
			case 'input':
				$td = Html::td($desc,'confclass');
				$td .= Html::td('<input name="data['.$name.']" type="text" value="" />','confclass');
				$tr .= Html::tr($td);
				break;
			case 'textarea':
				$td = Html::td($desc,'confclass');
				$td .= Html::td('<textarea name="data['.$name.']" style="width:300px;height:150px;"></textarea>','confclass');
				$tr .= Html::tr($td);
				break;
			case 'select':
				$ret = '<select name="data['.$name.']">';
				if ((gettype($vars) !== gettype(array())) or !count($vars) ) {
					$ret .= '<option value=""></option></select>';
				} else {
					foreach ($vars as $key => $value){
						$ret .= '<option value="'.$key.'">'.$value.'</option>';
					}
					$ret .= '</select>';

					$td = Html::td($desc,'confclass');
					$td .= Html::td($ret,'confclass');
					$tr .= Html::tr($td);
				}
				break;
		}
	}
	$but = '<input type="submit" value="'.__('Додати').'" />';
	Aurus::getInstance()->addContent( Aurus::getInstance()->form_start().Html::table($tr).$but.'</form>');
}